package com.supermap.expertinfo.service.impl;

import com.supermap.common.JSONUtil;
import com.supermap.expertinfo.dao.ExpertInfoDao;
import com.supermap.expertinfo.entity.ExpertInfo;
import com.supermap.expertinfo.service.ExpertInfoService;
import com.supermap.farmland.service.impl.FarmlandServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ExpertInfoServiceImpl implements ExpertInfoService {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(ExpertInfoServiceImpl.class);

    @Resource
    private ExpertInfoDao expertInfoDao;

    @Override
    public JSONUtil getPositiveExpertByArea(String count, String[] areaCode) {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            //获取某地区前n个活跃的专家列表，并返回活跃度
            List<ExpertInfo> data = expertInfoDao.getPositiveExpertByArea(Integer.valueOf(count), areaCode);

            //获取某地区前n个活跃的专家列表，并返回活跃度
            jsonUtil.setMsg("Get user farmlands success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(data);
        } catch (Exception e) {
            //捕捉数据库异常
            logger.error("FarmlandServiceImpl=>getFarmlandCountByArea=>DaoException:" + e.getMessage());
            jsonUtil.setMsg("Get FarmlandCountByArea flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }
}
